package zipcode.controller;

import java.sql.SQLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import zipcode.model.ZipcodeService;

@Controller
public class Zipcode {
	ZipcodeService zipcodeService;
	public Zipcode(ZipcodeService zipcodeSerivce){
		this.zipcodeService = zipcodeSerivce;
	}
	@RequestMapping(value="zipcode.do")
	public ModelAndView zipcode(HttpServletRequest request, Map<String,Object> map) throws SQLException{
		HashMap<String,Object> condition = new HashMap<>();
		Enumeration<?> paramNames  = request.getParameterNames();
		while(paramNames.hasMoreElements()){
			String paramName = paramNames.nextElement().toString();
			condition.put(paramName, request.getParameter(paramName));
		}
		map.put("address", zipcodeService.selectZipcode(condition));
		return new ModelAndView("jsonview",map);
	}
}
